package com.example.evanproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.evanproject.domain.News;
import com.example.evanproject.service.NewsService;
import com.example.evanproject.mapper.NewsMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
* @author hanxiaoqi
* @description 针对表【news】的数据库操作Service实现
* @createDate 2024-03-09 21:52:13
*/
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News>
    implements NewsService{

    @Autowired
    private NewsMapper newMapper;



    /*查询所有列表按照分页查询*/
    public List<News> selectall(String title, String time1, String time2, Integer typeid, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        return newMapper.selectlist(title, time1, time2, typeid);
    }


    //获取全部的新闻新闻
    public  List<News> selectalllist(){
        String title=null;
        String time1=null;
        String time2=null;
        Integer typeid=null;
        return newMapper.selectlist(title, time1, time2, typeid);
    }


    public News selectnewbyid(Integer newId) {

        return newMapper.selectnewbyid(newId);
    }



    public Integer addnew(String iTitle, String iAuthor, String iContent, Integer typeId) {
//获取当前时间带有时分秒
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        String time= dateFormat.format(date);
        return  newMapper.addnew(iTitle,iAuthor,iContent,typeId,time);
    }

    @Override
    public List<News> selectall2() {
        return newMapper.selectall2();
    }

}




